// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2019-2025, The OpenROAD Authors

#pragma once

#include "dbCore.h"
#include "odb/dbId.h"
#include "odb/dbTypes.h"
#include "odb/dbViaParams.h"
#include "odb/odb.h"

namespace odb {

class _dbBox;
class _dbTechLayer;
class _dbTechViaGenerateRule;
class _dbTechNonDefaultRule;
class _dbDatabase;
class dbIStream;
class dbOStream;

struct _dbTechViaFlags
{
  uint _default_via : 1;
  uint _top_of_stack : 1;
  uint _has_params : 1;
  uint _spare_bits : 29;
};

class _dbTechVia : public _dbObject
{
 public:
  // PERSISTANT-MEMBERS
  _dbTechViaFlags _flags;
  double _resistance;
  char* _name;
  char* _pattern;
  dbId<_dbBox> _bbox;  // Caching the bbox speeds up defin imports.
  dbId<_dbBox> _boxes;
  dbId<_dbTechLayer> _top;     // Caching the layer speeds up defin imports.
  dbId<_dbTechLayer> _bottom;  // Caching the layer speeds up defin imports.
  dbId<_dbTechNonDefaultRule> _non_default_rule;  // non-default-rule
  dbId<_dbTechViaGenerateRule>
      _generate_rule;        // via generated by tech-via-rule, 5.6 DEF
  _dbViaParams _via_params;  // params used to generate this via, 5.6 DEF
  dbId<_dbTechVia> _next_entry;

  _dbTechVia(_dbDatabase*, const _dbTechVia& v);
  _dbTechVia(_dbDatabase*);
  ~_dbTechVia();

  bool operator==(const _dbTechVia& rhs) const;
  bool operator!=(const _dbTechVia& rhs) const { return !operator==(rhs); }
  void collectMemInfo(MemInfo& info);
};

dbOStream& operator<<(dbOStream& stream, const _dbTechVia& via);
dbIStream& operator>>(dbIStream& stream, _dbTechVia& via);

}  // namespace odb
